package com.xnyzc.lhy.mis.controller.cmsapi.coupon;


import com.xnyzc.lhy.common.entity.CouponRv;
import com.xnyzc.lhy.common.exception.CouponException;
import com.xnyzc.lhy.common.penum.coupon.CouponErrorCode;
import com.xnyzc.lhy.mis.entity.coupon.CouponGroupSearchResult;
import com.xnyzc.lhy.mis.service.coupon.IOaSysCouponGroupService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 优惠券组合 前端控制器
 * </p>
 *
 * @author haoyfa
 * @since 2019-12-27
 */
@Slf4j
@RestController
@RequestMapping("/coupon/couponGroup")
public class OaSysCouponGroupController {
    @Autowired
    IOaSysCouponGroupService iOaSysCouponGroupService;

    /**
     * 获取优惠券分组记录（根据批次ID）
     *
     * @return
     */
    @ApiOperation(value = "获取优惠券分组记录（根据批次ID）", notes = "获取优惠券分组记录（根据批次ID）")
    @GetMapping(value = "/queryCouponGroupList")
    public CouponRv queryCouponGroupList(@RequestParam("batchId") String batchId) {
        try {
            List<CouponGroupSearchResult> couponGroupSearchResult = iOaSysCouponGroupService.queryCouponGroupList(batchId);
            return CouponRv.wrapSuccess(couponGroupSearchResult);
        }
        catch (CouponException ae){
            log.error("获取优惠券分组记录（根据批次ID） 失败：" + ae.getErrno().getDesc());
            return CouponRv.wrapErrorCode(ae.getErrno());
        }
        catch (Exception ex){
            log.error("获取优惠券分组记录（根据批次ID） 失败：" + CouponErrorCode.unKnow.getDesc());
            return CouponRv.wrapErrorCode(CouponErrorCode.unKnow);
        }
    }
}
